package com.company.project.controller.store;

import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.SysStoreAlbumEntity;
import com.company.project.service.SysStoreAlbumService;



/**
 * 
 *
 * @author YangYulin
 * @email YangYulinit@163.com
 * @date 2020-08-05 16:20:50
 */
@Controller
@RequestMapping("/")
@Api(tags = "门店管理-门店相册")
public class SysStoreAlbumController {
    @Autowired
    private SysStoreAlbumService sysStoreAlbumService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/sysStoreAlbum")
    public String sysStoreAlbum() {
        return "sysstorealbum/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("sysStoreAlbum/add")
    @RequiresPermissions("sysStoreAlbum:add")
    @ResponseBody
    public DataResult add(@RequestBody SysStoreAlbumEntity sysStoreAlbum){
        sysStoreAlbumService.save(sysStoreAlbum);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("sysStoreAlbum/delete")
    @RequiresPermissions("sysStoreAlbum:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        sysStoreAlbumService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("sysStoreAlbum/update")
    @RequiresPermissions("sysStoreAlbum:update")
    @ResponseBody
    public DataResult update(@RequestBody SysStoreAlbumEntity sysStoreAlbum){
        sysStoreAlbumService.updateById(sysStoreAlbum);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("sysStoreAlbum/listByPage")
    @RequiresPermissions("sysStoreAlbum:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody SysStoreAlbumEntity sysStoreAlbum){
        Page page = new Page(sysStoreAlbum.getPage(), sysStoreAlbum.getLimit());
        QueryWrapper queryWrapper = new QueryWrapper();
        //查询条件示例
        //queryWrapper.eq("id", sysStoreAlbum.getId());
        queryWrapper.eq("store_id",sysStoreAlbum.getStoreId());
        IPage<SysStoreAlbumEntity> iPage = sysStoreAlbumService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
